/** \file    io_types.cpp
  * \brief   Definition of types used in images input/output.
  * \date    2002, 2003
  * \author  Fedor Chelnokov
  * \version $Header: /home/cscom1r4/cvsroot/cs/imglib/src/io_types.cpp,v 1.1 2004/02/04 14:43:23 cscom1r4 Exp $
  */

#include "imglib/io_types.h"

namespace img {

////////////////////////////
// ext_vec implementation //
////////////////////////////

ext_vec::operator std::string() const
{
	std::string s, l;
	ext_vec::const_iterator i;
	for (i = begin(); i != end(); ++i) {
		if (!l.empty())
			l += ", ";
		if (l.size() >= 79) {
			s += l +'\n';
			l.erase();
		}
		l += *i;
	}
	s += l;
	return s;
}

std::string ext_vec::search_str() const
{
	std::string s;
	ext_vec::const_iterator i;
	for (i = begin(); i != end(); ++i) {
		if (!s.empty())
			s += ';';
		s += "*.";
		s += *i;
	}
	return s;
}

bool ext_vec::inside(const std::string &ext) const
{
	std::string u(ext);
	std::string::iterator i;
	for (i = u.begin(); i != u.end(); ++i)
		*i = toupper(*i);

	return std::find(begin(), end(), u) != end();
}

void ext_vec::unite(const ext_vec &rhs)
{
	ext_vec::const_iterator i;
	for (i = rhs.begin(); i != rhs.end(); ++i)
		if (std::find(begin(), end(), *i) == end())
			push_back(*i);
}

void ext_vec::intersect(const ext_vec &rhs)
{
	ext_vec intersection;
	ext_vec::const_iterator i;
	for (i = rhs.begin(); i != rhs.end(); ++i)
		if (std::find(begin(), end(), *i) != end())
			intersection.push_back(*i);
	swap(intersection);
}

void ext_vec::sort()
{
	std::sort(begin(), end());
}

} //namespace img
